package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.ResetRadioGroupEvent;
	import com.tongji.housediy.events.commonEvent.ShowComplementInforEvent;
	import com.tongji.housediy.events.TypeXMLAdminEvent;
	import com.tongji.housediy.utils.ShowCustomToolTip;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class FurnitureCompMediator extends Mediator
	{
		[Inject]
		public var view:FurnitureComp;
		
		override public function onRegister():void
		{
			view.roomBtn.addEventListener(MouseEvent.CLICK, roomBtnClickHandler);
			view.brandBtn.addEventListener(MouseEvent.CLICK, brandBtnClickHandler);
			view.functionBtn.addEventListener(MouseEvent.CLICK, functionBtnClickHandler);
			this.addContextListener(ShowComplementInforEvent.SHOW_COMPLEMENT_INFOR, showComplementInfor, ShowComplementInforEvent);
			
			this.addContextListener(ResetRadioGroupEvent.RESET_FURNITURE_RADIO, resetRadioHandler, ResetRadioGroupEvent);
		}
		
		private function showComplementInfor(event:ShowComplementInforEvent):void
		{
			var showToolTip:ShowCustomToolTip = new ShowCustomToolTip(view.roomBtn, "请将家具直接拖放至场景，并单击家具可查看产品详情。");
		}
		
		private function resetRadioHandler(event:ResetRadioGroupEvent):void
		{
			view.furnitureGroup.selection = view.roomBtn;
		}
		
		private function roomBtnClickHandler(event:MouseEvent):void
		{
			view.furnitureGroup.selection = view.roomBtn;
			dispatch(new TypeXMLAdminEvent(TypeXMLAdminEvent.UPDATE_FURNITURE_LEVEL1_XML, "room"));
		}
		
		private function brandBtnClickHandler(event:MouseEvent):void
		{
			view.furnitureGroup.selection = view.brandBtn;
			dispatch(new TypeXMLAdminEvent(TypeXMLAdminEvent.UPDATE_FURNITURE_LEVEL1_XML, "brand"));
		}
		
		private function functionBtnClickHandler(event:MouseEvent):void
		{
			view.furnitureGroup.selection = view.functionBtn;
			dispatch(new TypeXMLAdminEvent(TypeXMLAdminEvent.UPDATE_FURNITURE_LEVEL1_XML, "function"));
		}
	}
}